<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改用户权限</title>
	<link rel="stylesheet" href="/static/layui/assets/css/layui.css">
    <link rel="stylesheet" href="/static/layui/assets/css/view.css"/>
    <link rel="icon" href="/favicon.ico">
 
    <title>管理后台</title>
</head>
<body class="layui-view-body">
    <div class="layui-content">
        <div class="layui-row">
            <div class="layui-card">
                <div class="layui-card-body" >
                    <div class="form-box">
                        <div class="layui-form layui-form-item">
                            <div class="layui-inline">
                                <div class="layui-form-mid">行数:</div>
                                <div class="layui-input-inline" style="width: 50px;">
                                  <input type="text" autocomplete="off" name="limit" id="pagesize" class="layui-input" onkeyup="value=value.replace(/[^\d]/g,'')" onchange="touserpower(value)" th:value="${pagesize}">
                                </div>
                                <button class="layui-btn layui-btn-blue" onclick="window.location.reload()">刷新</button>
                            </div>
                        </div>
                        <div id="">
                        	<table class="layui-table" >
							  <thead>
							    <tr style="text-align: center;">
							   	  <th style="text-align: center;">编号</th>
							      <th style="text-align: center;">姓名</th>
							      <th style="text-align: center;">账号</th>
							      <th style="text-align: center;">身份证</th>
							      <th style="text-align: center;">电话</th>
							      <th style="text-align: center;">备注</th>
							      <th style="text-align: center;">删除发票权限</th>
							    </tr> 
							  </thead>
							  <tbody id="tbody">
							  </tbody>
							</table>
							<div>  
								<div style="float: left;line-height:50px;">
									共<span id='totalElements'></span>条数据&emsp;
									第<span id='etNumber'>1</span>页/共<span id='totalPages'></span>页
								</div>
	                        	<div id="page"  style="text-align:right;"></div>
                        	</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="/static/layui/assets/layui.js" th:inline="none" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/jquery-1.4.4.min.js"></script>
</body>
<script type="text/javascript" th:inline="none">
var pagesize=$('#pagesize').val();
/* 分页 */
layui.use(['laypage', 'layer'], function(){
	var laypage = layui.laypage ,layer = layui.layer;
	var url='powerpage';
	$.post(url,function(count){
		var pagecount = count/pagesize;
		console.log('总记录数：'+count+',总页数：'+pagecount);
		laypage.render({
			elem:'page',
			count:pagecount*10, //总共的数据
		    jump: function(obj){
		      var pageindex=obj.curr;
		      loaduserlist(pageindex);
		    }
		  });
	});
});
	/* 加载第X页数据 */
	function loaduserlist(pageindex){
		console.log('第' + pageindex + '页');
		var url="powerlist?pageindex="+pageindex+"&pagesize="+pagesize;
		$.post(url,function(user){
			var html="";
			var b=1;
			$.each(user.content,function (n,value) {
				html +='<tr  style="text-align: center;">';
				html +='	<td >'+b+'</td>';
				html +='	<td >'+value.name+'</td>';
				html +='	<td >'+value.username+'</td>';
				html +='	<td >'+value.sfz+'</td>';
				html +='	<td >'+value.number+'</td>';
				html +='	<td >'+value.remark+'</td>';
				if(value.ql==null){
					html +='	<td >';
					html +='	 <button onclick="but('+value.id+','+b+')" id="butt'+b+'" class="layui-btn layui-btn-primary layui-btn layui-btn-xs">无权限</button>';
					html +='</td>';
				}else{
					html +='	<td >';
					html +='	 <button onclick="but('+value.id+','+b+')" id="butt'+b+'" class="layui-btn layui-btn-normal layui-btn layui-btn-xs">有权限</button>';
					html +='</td>';
				}
				html +='</tr>';
				b=b+1;
			})
			$('#tbody').html(html);
			/* 提示 */
			$('#totalElements').html(user.totalElements);
			$('#etNumber').html(user.number+1);
			$('#totalPages').html(user.totalPages);
		},'json')
	}
	function touserpower(value){
		window.location.href="userpower?pagesize="+value; 
	}
	
	function but(value,b){
		var com=$('#butt'+b).html();
		var yql="无权限";
		if(com==yql){
			$.post('powerup?id='+value,function(user){ 
				$('#butt'+b).removeClass("layui-btn layui-btn-primary layui-btn layui-btn-xs").addClass("layui-btn layui-btn-normal layui-btn layui-btn-xs");
				$('#butt'+b).html('有权限');
				layer.msg('该用户已拥有删除发票的权限');
			});
		}else{
			$.post('powerdown?id='+value,function(user){ 
				$('#butt'+b).removeClass("layui-btn layui-btn-normal layui-btn layui-btn-xs").addClass("layui-btn layui-btn-primary layui-btn layui-btn-xs");
				$('#butt'+b).html('无权限');
				layer.msg('该用户已丧失使用权限');
			});
		}
	}
</script>
</html>